package org.ioriframework.plugin.maven.preferences;

import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.ioriframework.plugin.maven.Activator;
import org.ioriframework.plugin.maven.Constants;
import org.ioriframework.plugin.maven.util.StringUtils;

/**
 * Class used to initialize default preference values.
 */
public class PreferenceInitializer extends AbstractPreferenceInitializer {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
	 */
	public void initializeDefaultPreferences() {
		IPreferenceStore store = Activator.getDefault().getPreferenceStore();
		// 从环境变量中取Maven目录,作为默认值
		String mavenHome = System.getenv("M2_HOME");
		if (StringUtils.isNullOrEmpty(mavenHome)) {
			mavenHome = System.getenv("MAVEN_HOME");
		}
		store.setDefault(Constants.P_MAVEN_HOME, StringUtils.isNullOrEmpty(mavenHome) ? "" : mavenHome);
		// 日志输出默认字符集
		store.setDefault(Constants.P_LOG_ENCODING, "GBK");
		// 默认执行单元测试
		store.setDefault(Constants.P_SKIP_TEST, false);
	}

}
